package com.youlai.boot.modules.game.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.game.model.form.GameCommentForm;
import com.youlai.boot.modules.game.model.query.GameCommentQuery;
import com.youlai.boot.modules.game.model.vo.GameCommentVO;
import com.youlai.boot.modules.game.service.GameCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 游戏评论控制器
 *
 * @author 有来技术团队
 */
@Tag(name = "游戏评论接口")
@RestController
@RequestMapping("/api/v1/game/comments")
@RequiredArgsConstructor
public class GameCommentController {

    private final GameCommentService gameCommentService;

    @Operation(summary = "获取评论分页列表")
    @GetMapping("/page")
    public PageResult<GameCommentVO> getCommentPage(
            @ParameterObject GameCommentQuery queryParams
    ) {
        Page<GameCommentVO> page = gameCommentService.getCommentPage(queryParams);
        return PageResult.success(page);
    }

    @Operation(summary = "获取评论详情")
    @GetMapping("/{id}")
    public Result<GameCommentVO> getCommentDetail(
            @Parameter(description = "评论ID") @PathVariable Long id
    ) {
        GameCommentVO comment = gameCommentService.getCommentDetail(id);
        return Result.success(comment);
    }

    @Operation(summary = "添加评论")
    @PostMapping
    public Result<Long> addComment(
            @Validated @RequestBody GameCommentForm formData
    ) {
        Long id = gameCommentService.addComment(formData);
        return Result.success(id);
    }

    @Operation(summary = "修改评论")
    @PutMapping("/{id}")
    public Result<Boolean> updateComment(
            @Parameter(description = "评论ID") @PathVariable Long id,
            @Validated @RequestBody GameCommentForm formData
    ) {
        boolean result = gameCommentService.updateComment(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除评论")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteComment(
            @Parameter(description = "评论ID") @PathVariable Long id
    ) {
        boolean result = gameCommentService.deleteComment(id);
        return Result.judge(result);
    }

    @Operation(summary = "评论点赞/取消点赞")
    @PostMapping("/{id}/like")
    public Result<Boolean> toggleLike(
            @Parameter(description = "评论ID") @PathVariable Long id
    ) {
        boolean result = gameCommentService.toggleLike(id);
        return Result.judge(result);
    }
} 